package com.it.gw.modules.water.activity

import android.view.View
import androidx.activity.viewModels
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2
import com.it.common.view.CommonViewPager2Adapter
import com.it.gw.R
import com.it.gw.base.BaseActivity
import com.it.gw.databinding.ActivityWaterMainBinding
import com.it.gw.modules.water.fragment.ReservoirSeeFragment
import com.it.gw.modules.water.fragment.ReservoirUploadFragment
import com.it.gw.modules.water.fragment.WaterConservancyFragment
import com.it.gw.modules.water.fragment.WaterRecordFragment
import com.it.gw.modules.water.viewmodel.WaterViewModel


class WaterMainActivity : BaseActivity<ActivityWaterMainBinding>() {
    private val fragmentList by lazy { mutableListOf<Fragment>() }
    val waterViewModel by viewModels<WaterViewModel>()

    companion object {
        const val TAG = "WaterMainActivity"
    }


    override fun initObserver() {

    }


    override fun initListener() {
        binding.rlUpload.setOnClickListener {
            binding.vContent.currentItem = 0


        }
        binding.rlSee.setOnClickListener {
            binding.vContent.currentItem = 1

        }
        binding.vContent.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                if (position == 0) {
                    binding.tvUpload.setTextColor(
                        ContextCompat.getColor(
                            this@WaterMainActivity,
                            R.color.color_0F6AF8
                        )
                    )
                    binding.vLine1.visibility = View.VISIBLE
                    binding.tvSee.setTextColor(
                        ContextCompat.getColor(
                            this@WaterMainActivity,
                            R.color.color_999999
                        )
                    )
                    binding.vLine2.visibility = View.INVISIBLE

                } else {
                    binding.tvSee.setTextColor(
                        ContextCompat.getColor(
                            this@WaterMainActivity,
                            R.color.color_0F6AF8
                        )
                    )
                    binding.vLine2.visibility = View.VISIBLE
                    binding.tvUpload.setTextColor(
                        ContextCompat.getColor(
                            this@WaterMainActivity,
                            R.color.color_999999
                        )
                    )
                    binding.vLine1.visibility = View.INVISIBLE

                }
            }

        })

    }


    override fun initData() {

    }

    private val reservoirUploadFragment by lazy { WaterConservancyFragment() }
    private val reservoirSeeFragment by lazy { WaterRecordFragment() }
    override fun initView() {
        setTitle(
            title = R.string.str_water_base,
            isBack = true,

            )

        fragmentList.add(reservoirUploadFragment)
        fragmentList.add(reservoirSeeFragment)
        binding.vContent.isUserInputEnabled = false
        binding.vContent.adapter =
            CommonViewPager2Adapter(supportFragmentManager, lifecycle, fragmentList)
        binding.vContent.offscreenPageLimit = 2

    }


    override fun setContentView() {
        binding = ActivityWaterMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
    }


}